#ifndef _FITTING_HH_
#define _FITTING_HH_

#include "cxcore.h"

#include <boost/smart_ptr.hpp>

#include <gsl/gsl_multimin.h>

#include "basic_utils.hh"
#include "AppearanceBase.hh"

const unsigned int DEFAULT_GRID_SIZE = 4;
const unsigned int DEFAULT_GRID_STEP = 5; //in pixels.


const double NM_COEFF_STEP_SIZE = DEFAULT_GRID_STEP;

typedef enum DistanceType {SSD = CV_TM_SQDIFF_NORMED, 
			   NCC =  CV_TM_CCORR_NORMED, 
			   ZNCC =  CV_TM_CCOEFF_NORMED,
			   MI} DistanceType;

double eval_distance(const IplImage *src1, const IplImage *src2, DistanceType distT = SSD);
double eval_projection_error(const IplImage *image, AppearanceBase& app_base, DistanceType distT = SSD);

CvPoint fit_patch_xy(const IplImage *image, const IplImage *patch, CvPoint seed,
		     std::vector<double>& matches, DistanceType distT, 
		     unsigned int grid_size, unsigned int grid_step); 



#endif
